package com.yuexun.dhdoctor.module.meetingNew.presenter.impl;

import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.bean.model.HelpFileEntity;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewTypeBean;
import com.yuexun.dhdoctor.module.meetingNew.model.IMeetingNewModel;
import com.yuexun.dhdoctor.module.meetingNew.presenter.IMeetingNewTypeListPresenter;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewTypeListView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wangt on 2018/6/28.
 */
public class MeetingNewTypeListPresenter implements IMeetingNewTypeListPresenter {
    private IMeetingNewModel model;
    private IMeetingNewTypeListView view;

    public MeetingNewTypeListPresenter(IMeetingNewModel model, IMeetingNewTypeListView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getTypeList(Map<String, String> praise) {
        model.getTypeList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<MeetingNewTypeBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<MeetingNewTypeBean> bean) {
                        view.getTypeList(bean);
                    }
                });
    }

    @Override
    public void getTypeDetail(Map<String, String> praise) {
        model.getTypeDetail(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<HelpFileEntity>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<HelpFileEntity> bean) {
                        view.getTypeDetail(bean);
                    }
                });
    }
}
